package com.changgou.service.impl;

import com.changgou.dao.OrderInfoMapper;
import com.changgou.feign.ItemInfoFeign;
import com.changgou.pojo.OrderInfo;
import com.changgou.service.OrderInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author: hushengjin
 */
@Service
public class OrderInfoServiceImpl implements OrderInfoService {

    @Autowired
    private OrderInfoMapper orderInfoMapper;
    @Autowired
    private ItemInfoFeign itemInfoFeign;

    /**
     * 创建订单
     *
     * @param username
     * @param id
     * @param count
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void add(String username, int id, int count) {
        //生成订单
        OrderInfo orderInfo = new OrderInfo();
        orderInfo.setMessage("生成订单");
        orderInfo.setMoney(10);
        int i = orderInfoMapper.insertSelective(orderInfo);
        System.out.println("受影响的行数:" + i);

        //库存递减
        itemInfoFeign.decrCount(id, count);
    }
}
